package com.example.myapplication.Adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.Bean.OrderBean;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class OrderAdapter extends BaseAdapter {
    List<OrderBean> list=new ArrayList<>();
    Activity activity;

    public OrderAdapter(List<OrderBean> list, Activity activity) {
        this.list = list;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return list.size();
    }
    //获取list中的数据
    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        //通过布局修改数据要activity
        view= LayoutInflater.from(activity).inflate(R.layout.ordermokuai,null);
        //修改数据
        ImageView imageView=view.findViewById(R.id.ordermokuai_img);
        TextView name=view.findViewById(R.id.ordermokuai_name);
        TextView address=view.findViewById(R.id.ordermokuai_address);
        TextView prace=view.findViewById(R.id.ordermokuai_prace);
        TextView danwei=view.findViewById(R.id.ordermokuai_danwei);

        imageView.setImageResource(list.get(i).getImg());
        name.setText(list.get(i).getName());
        address.setText(list.get(i).getAddress());
        prace.setText(list.get(i).getPrice());
        danwei.setText(list.get(i).getDanwei());
        return view;
    }
}
